<!DOCTYPE html>
<html>

<head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    <script type="text/javascript">

        function register() {
            var str1 = document.getElementById("name").value;
            var str2 = document.getElementById("psd").value;
            var str3 = document.getElementById("psd1").value;
            if (str1 == "" || str2 == "" || str3 == "") {
                alert("用户名或密码不能为空");
                document.getElementById("name").focus();
                return false;
            }
            else if (str1.length() < 4) {
                alert("用户名长度过短");
                document.getElementById("name").focus();
                return false;
            }
            else if (str1.length() > 10) {
                alert("用户名长度过长");
                document.getElementById("name").focus();
                return false;
            }
            else if (str2.length() < 6) {
                alert("密码长度过短");
                document.getElementById("psd").focus();
                return false;
            }
            else if (str2.length() > 15) {
                alert("密码长度过长");
                document.getElementById("psd").focus();
                return false;
            }
            else if (str2 != str3) {
                alert("两次密码不一致");
                document.getElementById("psd1").focus();
                return false;
            }
        }

        function validate() {
            var flag = register();
            if (flag == false)
                return false;
            return true;
        }


    </script>
</head>

<body>
    <form action="action.jsp" name="myform" onsubmit="return validate()" method="post">
        <p>请输入用户名：<input type="text" name="name" placeholder="请输入2-10个字符">
            <p>请输入密码:&nbsp&nbsp&nbsp<input type="password" name="psd" placeholder="请输入6-18个字符">
                <p>请确认密码:&nbsp&nbsp&nbsp<input type="password" name="psd1">
                    <p><input type="submit" name="submit" value="注册">
                        <input type="reset" name="reset" value="置空">
    </form>
</body>

</html>